package com.moive.news.tqnewsapplication.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.moive.news.tqnewsapplication.R;
import com.moive.news.tqnewsapplication.ui.activity.PutNewsActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/12/21.
 */

public class JiudiandelAdapter extends RecyclerView.Adapter<JiudiandelAdapter.ViewHolder> {
    private Context context;
    private LayoutInflater mInflater;
    private List<String> list;
    private OnItemActionListener mOnItemActionListener;
    public JiudiandelAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = mInflater.inflate(R.layout.jiudian_deil_item, null, false);
        ViewHolder viewHolder = new ViewHolder(v);
        viewHolder.setIsRecyclable(true);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.jiudian_deil_tv.setText(list.get(position).toString());
        if (mOnItemActionListener != null){
            holder.ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemActionListener.onItemClickListener(v,holder.getPosition());
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public  class ViewHolder extends RecyclerView.ViewHolder {
        public TextView jiudian_deil_tv;
        private LinearLayout ll;
        public ViewHolder(View itemView) {
            super(itemView);
            jiudian_deil_tv= (TextView) itemView.findViewById(R.id.jiudian_deil_tv);
            ll=itemView.findViewById(R.id.ll);
        }
    }
    public interface OnItemActionListener{
        void onItemClickListener(View v, int pos);
    }
    public void setOnItemActionListener(OnItemActionListener onItemActionListener){
        this.mOnItemActionListener = onItemActionListener;
    }
}
